﻿@model TopMenuModel
@using Nop.Core.Domain
@using Nop.Core.Infrastructure
@using Nop.Web.Models.Catalog;
@{
    var isRtl = this.ShouldUseRtlTheme();
    var supportResponsive = EngineContext.Current.Resolve<StoreInformationSettings>().ResponsiveDesignSupported;
}
@helper RenderCategoryLine(CategorySimpleModel category, int level, bool responsiveMobileMenu)
{
    <a class="@if (category.SubCategories.Count > 0) { <text>dropdown-toggle</text> }else{ <text></text> }" href="@if (category.SubCategories.Count > 0) { <text></text> }else{ @Url.RouteUrl("Category", new { SeName = category.SeName }) }">
        @category.Name
    @if (category.NumberOfProducts.HasValue)
    {
        <text> </text>@T("Categories.TotalProducts", category.NumberOfProducts.Value)
    }
    </a>

    var levelClass = "";
    if (level == 0)
    {
        levelClass = "firstLevel";
    }
    if (category.SubCategories.Count > 0)
    {
        <ul class="dropdown-menu @levelClass" data-role="dropdown">
            @foreach (var subCategory in category.SubCategories)
            {
                <li>
                    <a class="dropdown-toggle" href="@Url.RouteUrl("Category", new { SeName = subCategory.SeName })">@subCategory.Name
                        @if (subCategory.NumberOfProducts.HasValue)
                        {
                            <text> </text>@T("Categories.TotalProducts", subCategory.NumberOfProducts.Value)
                        }
                    </a>
                </li>
            }
        </ul>
    }
}

<header class="bg-cyan">
    <nav class="navigation-bar fixed-top">
        <nav class="navigation-bar-content container" id="overflow">
            @Html.Widget("header_menu_before")
            @*<a href="/" class="element no-large"><span class="icon-grid-view"></span> nopMetroUI <sup>1.0</sup></a>*@
            <a href="@Url.RouteUrl("CustomerInfo")" class="element no-desktop"><span class="icon-grid-view"></span> @WorkContext.CurrentCustomer.Username</a>
            @if (Model.Categories.Count > 0)
            {
                <a class="pull-menu" href="#"></a>
                <ul class="element-menu">
                    @* shopping cart for responsive menu *@
                    <li>
                        <div class="element no-desktop">
                            <i class="icon-cart place-left">&nbsp;</i>
                            <a href="@Url.RouteUrl("ShoppingCart")">@T("ShoppingCart")</a>
                        </div>
                    </li>
                    @* Login/Logout/Register for responsive menu *@
                    @if (String.IsNullOrEmpty(WorkContext.CurrentCustomer.Username))
                    {
                        <li>
                            <div class="element no-desktop">
                                <i class="icon-enter place-left">&nbsp;</i>
                                <a href="@Url.RouteUrl("Login")">@T("Account.Login")</a>
                            </div>
                        </li>
                        <li>
                            <div class="element no-desktop">
                                <i class="icon-clipboard-2 place-left">&nbsp;</i>
                                <a href="@Url.RouteUrl("Register")">@T("Account.Register")</a>
                            </div>
                        </li>
                    }
                    else
                    {
                        <li>
                            <div class="element no-desktop">
                                <i class="icon-exit place-left">&nbsp;</i>
                                <a href="@Url.RouteUrl("Logout")">@T("Account.Logout")</a>
                            </div>
                        </li>
                    }
                    @* show categories *@
                    @foreach (var category in Model.Categories)
                    {
                        <li>
                            @if (category.SubCategories.Count > 0)
                            {
                                @RenderCategoryLine(category, 0, false)
                            }
                            else
                            {                                
                                <div class="element">
                                    @RenderCategoryLine(category, 0, false)
                                </div>
                            }
                        </li>
                    }
                </ul>
            }

            <div id="menu-links-right" class="no-phone no-tablet-portrait no-desktop on-large">
            
                @*<div class="element input-element place-right no-tablet-portrait no-phone">*@
                    @*@Html.Action("SearchBox", "Catalog")*@
                <span class="element-divider place-right no-tablet-portrait no-phone"></span>
                    <a title="search" id="open-search" class="element place-right no-tablet-portrait no-phone" href="#"><span class="icon-search"></span></a>
                @*</div>*@

                <span class="element-divider place-right no-tablet-portrait no-phone"></span>

                @Html.Action("HeaderLinks", "Common")

                <span class="element-divider place-right no-tablet-portrait no-phone"></span>

            </div>

            @Html.Widget("header_menu_after")
        </nav>
    </nav>
</header>